package com.jhgsys.internal.accident.service.impl;

import com.jhgsys.internal.accident.entity.HazardExamineRectificationReturnRecord;
import com.jhgsys.internal.accident.mapper.HazardExamineRectificationReturnRecordMapper;
import com.jhgsys.internal.accident.service.IHazardExamineRectificationReturnRecordService;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.StringPool;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 *  Service实现
 *
 * @author zhangwei
 * @date 2024-08-22 17:40:29
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class HazardExamineRectificationReturnRecordServiceImpl extends ServiceImpl<HazardExamineRectificationReturnRecordMapper, HazardExamineRectificationReturnRecord> implements IHazardExamineRectificationReturnRecordService {

    /**
     * 查询（分页）
     * @author zhangwei
     * @date 2024-08-22 17:40:29
     * @param request QueryRequest
     * @param hazardExamineRectificationReturnRecord hazardExamineRectificationReturnRecord
     * @return IPage<HazardExamineRectificationReturnRecord>
    */
    @Override
    public IPage<HazardExamineRectificationReturnRecord> findHazardExamineRectificationReturnRecordPage(QueryRequest request, HazardExamineRectificationReturnRecord hazardExamineRectificationReturnRecord) {
        LambdaQueryWrapper<HazardExamineRectificationReturnRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HazardExamineRectificationReturnRecord::getDeletedFlg, 0);
        // TODO 设置查询条件

        Page<HazardExamineRectificationReturnRecord> page = new Page<>(request.getPageNum(), request.getPageSize());
        FebsUtil.pageWrapper(page, request);
        return this.page(page, queryWrapper);
    }

    /**
     * 查询（所有）
     * @author zhangwei
     * @date 2024-08-22 17:40:29
     * @param hazardExamineRectificationReturnRecord hazardExamineRectificationReturnRecord
     * @return List<HazardExamineRectificationReturnRecord>
     */
    @Override
    public List<HazardExamineRectificationReturnRecord> findHazardExamineRectificationReturnRecordList(HazardExamineRectificationReturnRecord hazardExamineRectificationReturnRecord) {
	    LambdaQueryWrapper<HazardExamineRectificationReturnRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HazardExamineRectificationReturnRecord::getDeletedFlg, 0);
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    /**
    * 根据ID查询
    * @author zhangwei
    * @date 2024-08-22 17:40:29
    * @param id
    * @return HazardExamineRectificationReturnRecord
    */
    @Override
    public HazardExamineRectificationReturnRecord findHazardExamineRectificationReturnRecordById(String id){
        return this.baseMapper.selectById(id);
    }

    /**
     * 新增
     * @author zhangwei
     * @date 2024-08-22 17:40:29
     * @param hazardExamineRectificationReturnRecord hazardExamineRectificationReturnRecord
     */
    @Override
    @Transactional
    public void createHazardExamineRectificationReturnRecord(HazardExamineRectificationReturnRecord hazardExamineRectificationReturnRecord) {
        hazardExamineRectificationReturnRecord.setCreatedTime(new Date());
        this.save(hazardExamineRectificationReturnRecord);
    }

    /**
     * 修改
     * @author zhangwei
     * @date 2024-08-22 17:40:29
     * @param hazardExamineRectificationReturnRecord hazardExamineRectificationReturnRecord
     */
    @Override
    @Transactional
    public void updateHazardExamineRectificationReturnRecord(HazardExamineRectificationReturnRecord hazardExamineRectificationReturnRecord) {
        hazardExamineRectificationReturnRecord.setUpdatedTime(new Date());
        this.saveOrUpdate(hazardExamineRectificationReturnRecord);
    }

    /**
     * 逻辑删除
     * @author zhangwei
     * @date 2024-08-22 17:40:29
     * @param hazardExamineRectificationReturnRecord hazardExamineRectificationReturnRecord
     * @param hazardExamineRectificationReturnRecordIds hazardExamineRectificationReturnRecordIds
     */
    @Override
    @Transactional
    public void deleteHazardExamineRectificationReturnRecord(HazardExamineRectificationReturnRecord hazardExamineRectificationReturnRecord,String hazardExamineRectificationReturnRecordIds) {
        List<String> list = Arrays.asList(hazardExamineRectificationReturnRecordIds.split(StringPool.COMMA));
        this.baseMapper.update(hazardExamineRectificationReturnRecord,new LambdaQueryWrapper<HazardExamineRectificationReturnRecord>().in(HazardExamineRectificationReturnRecord::getExamineAuditRecordId,list));
	}

    /**
    * 物理删除
    * @author zhangwei
    * @date 2024-08-22 17:40:29
    * @param hazardExamineRectificationReturnRecordIds hazardExamineRectificationReturnRecordIds
    */
    @Override
    @Transactional
    public void physicallyDeleteHazardExamineRectificationReturnRecord(String hazardExamineRectificationReturnRecordIds) {
        List<String> list = Arrays.asList(hazardExamineRectificationReturnRecordIds.split(StringPool.COMMA));
        LambdaQueryWrapper<HazardExamineRectificationReturnRecord> wapper = new LambdaQueryWrapper<>();
        wapper.in(HazardExamineRectificationReturnRecord::getExamineAuditRecordId,list);
        this.remove(wapper);
    }
}
